package com.ruoyi.project.simple.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.simple.domain.SplAdvertising;
import com.ruoyi.project.simple.service.ISplAdvertisingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 广告Controller
 * 
 * @author zhujj
 * @date 2020-01-15
 */
@RestController
@RequestMapping("/simple/simpleAdvertising")
public class SplAdvertisingController extends BaseController
{
    @Autowired
    private ISplAdvertisingService splAdvertisingService;

    /**
     * 查询广告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SplAdvertising splAdvertising)
    {
        startPage();
        List<SplAdvertising> list = splAdvertisingService.selectSplAdvertisingList(splAdvertising);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('simple:simpleAdvertising:export')")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SplAdvertising splAdvertising)
    {
        List<SplAdvertising> list = splAdvertisingService.selectSplAdvertisingList(splAdvertising);
        ExcelUtil<SplAdvertising> util = new ExcelUtil<SplAdvertising>(SplAdvertising.class);
        return util.exportExcel(list, "simpleAdvertising");
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('simple:simpleAdvertising:query')")
    @GetMapping(value = "/{advertisingId}")
    public AjaxResult getInfo(@PathVariable("advertisingId") Integer advertisingId)
    {
        return AjaxResult.success(splAdvertisingService.selectSplAdvertisingById(advertisingId));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('simple:simpleAdvertising:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SplAdvertising splAdvertising)
    {
        return toAjax(splAdvertisingService.insertSplAdvertising(splAdvertising));
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('simple:simpleAdvertising:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SplAdvertising splAdvertising)
    {
        return toAjax(splAdvertisingService.updateSplAdvertising(splAdvertising));
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('simple:simpleAdvertising:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advertisingIds}")
    public AjaxResult remove(@PathVariable Integer[] advertisingIds)
    {
        return toAjax(splAdvertisingService.deleteSplAdvertisingByIds(advertisingIds));
    }
}
